/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "InGameState.h"
#include "EntityManager.h"
#include "../EventManager.h"
#include "../Kernel.h"

extern Kernel* g_kernel;

InGameState::InGameState(void)
{
	entMng = EntityManager::GetInstance();
    SetName("InGameState");
}

/** Update the game world */
void InGameState::Update(float deltaTime)
{   
    
    m_playerCtrl.GatherEvents();    // retrieve player input
    m_gameRecorder.Update(deltaTime);
	m_aiMng.UpdateBrains();

    EventManager::GetInstance()->UpdateEventQueue( deltaTime );

    std::vector<ICamera*> camList = g_kernel->GetRenderer()->GetCameraList();
    std::vector<ICamera*>::iterator camIter = camList.begin();
    for(; camIter != camList.end(); ++camIter )
    {
        ICamera* cam = (*camIter);
        if ( cam->IsActivated() ) {
            cam->Update( deltaTime );
            if ( cam->IsMainCamera() )
                entMng->Update( deltaTime, cam );
        }
    }

}


/**
==========================
Retrieve the users input
==========================
*/
void InGameState::GetInput() 
{   
}

/** Close off everything */
void InGameState::Shutdown()
{
    entMng->DeletePlayer();
}

InGameState::~InGameState(void)
{

}
